/*
 * hal_fileio.h
 *
 *  Created on: 2025 Mar 27
 *      Author: SFLY
 */

#ifndef XTFOCLIB_HAL_DRIVERS_HAL_FILEIO_H_
#define XTFOCLIB_HAL_DRIVERS_HAL_FILEIO_H_
#include "driverlib.h"
#include "bsp_board_config.h"
//保存在flash里的电机参数结构体
typedef struct{
uint32_t motor_can_id;//电机CAN ID
uint32_t master_can_id;//主机CAN ID
uint32_t motor_elec_offset;//电机端电角度为0的值对应的编码器读取值
uint32_t motor_mech_offset;//电机端用户定义的零机械角度
uint32_t motor_orderdir;
int      motor_offset_lut[LUT_N];//电机端编码器误差值
#if ENCODER_STRUCT>0
uint32_t reducer_mech_offset;//减速器端用户定义的零机械角度
uint32_t reducer_orderdir;
#endif
float motor_pos_torque_kp;//电机运控模式的Kp值
float motor_pos_torque_kd;//电机运控模式的Kd值
float motor_speed_kp;     //电机速度环Kp值
float motor_speed_ki;     //电机速度环Ki值
float motor_pos_kp;       //电机位置环kp值
float motor_pos_ki;       //电机位置环ki值
float motor_pos_kd;       //电机位置环kd值
float motor_cur_kp;       //电机电流环kp值
float motor_cur_ki;       //电机电流环Ki值
uint32_t isUserDefFlag;      //用户是否在flash里存储了电机参数标识
float motor_limit_cur_max;//电流环限制
float motor_limit_spd_max;//速度环限制
uint32_t signflag;//数据符号标识 0x0001:电机电角度偏置为负号 0x0002:电机机械角度偏置为负 0x0004:电机编码器相序为负 0x0008:减速器机械角度偏置为负 0x0010:减速器编码器相序为负
}xt_hal_fileio_t;
/**file system config*************************************************************/
extern xt_hal_fileio_t g_stc_LogFile;

void Hal_Read_Motor_Param(xt_hal_fileio_t *pstc);
void Hal_Write_Motor_Param(xt_hal_fileio_t *pstc);
#endif /* XTFOCLIB_HAL_DRIVERS_HAL_FILEIO_H_ */
